﻿Imports System.Data.OleDb
Public Class addThesis
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

        Dim myGUID As New System.Guid
        myGUID = Guid.NewGuid()
        Dim newFileName = myGUID.ToString() + ".png"


        If f_logo.HasFile Then
            Dim picLocationOnServerHardDisk = Request.MapPath("pictures") & "/" & newFileName
            f_logo.SaveAs(picLocationOnServerHardDisk)

        End If

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("StocksConnectionString").ConnectionString)
        Dim SqlString As String = "Insert into Stocks(CompanyName,Industry,Ticker,Direction,PriceAtThesis,Logo,Thesis) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tb_companyname.Text)
        cmd.Parameters.AddWithValue("@f2", tb_industry.Text)
        cmd.Parameters.AddWithValue("@f3", tb_ticker.Text)
        cmd.Parameters.AddWithValue("@f4", tb_direction.Text)
        cmd.Parameters.AddWithValue("@f5", tb_price.Text)
        cmd.Parameters.AddWithValue("@f6", "pictures/" & newFileName)
        cmd.Parameters.AddWithValue("@f7", tb_thesis.Text)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("confirmation.aspx")
    End Sub
End Class